home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / STEP.C < prev    next >
C/C++ Source or Header  |  1992-01-14  |  5KB  |  166 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /scheme/src/microcode/RCS/step.c,v 9.30 1992/01/15 04:02:33 jinx Exp $
  4.  
  5. Copyright (c) 1987-92 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Support for the stepper */
  36.  
  37. #include "scheme.h"
  38. #include "prims.h"
  39.  
  40.                  /**********************************/
  41.                  /* Support of stepping primitives */
  42.                  /**********************************/
  43.  
  44. /* UGLY ... this knows (a) that it is called with the primitive frame
  45.    already popped off the stack; and (b) the order in which Save_Cont
  46.    stores things on the stack.
  47. */
  48.  
  49. static void
  50. DEFUN (Install_Traps, (Hunk3), SCHEME_OBJECT Hunk3)
  51. {
  52.   SCHEME_OBJECT Eval_Hook, Apply_Hook, Return_Hook;
  53.  
  54.   Stop_Trapping();
  55.   Eval_Hook = MEMORY_REF (Hunk3, HUNK_CXR0);
  56.   Apply_Hook = MEMORY_REF (Hunk3, HUNK_CXR1);
  57.   Return_Hook = MEMORY_REF (Hunk3, HUNK_CXR2);
  58.   Set_Fixed_Obj_Slot(Stepper_State, Hunk3);
  59.   Trapping = ((Eval_Hook != SHARP_F) |
  60.           (Apply_Hook != SHARP_F) |
  61.           (Return_Hook != SHARP_F));
  62.   return;
  63. }
  64.  
  65. /* (PRIMITIVE-EVAL-STEP EXPRESSION ENV HUNK3)
  66.    Evaluates EXPRESSION in ENV and intalls the eval-trap,
  67.    apply-trap, and return-trap from HUNK3.  If any
  68.    trap is '(), it is a null trap that does a normal EVAL,
  69.    APPLY or return.
  70. */
  71.  
  72. DEFINE_PRIMITIVE ("PRIMITIVE-EVAL-STEP", Prim_eval_step, 3, 3, 0)
  73. {
  74.   PRIMITIVE_HEADER (3);
  75.   CHECK_ARG (3, HUNK3_P);
  76.   {
  77.     SCHEME_OBJECT expression = (ARG_REF (1));
  78.     SCHEME_OBJECT environment = (ARG_REF (2));
  79.     SCHEME_OBJECT hooks = (ARG_REF (3));
  80.     PRIMITIVE_CANONICALIZE_CONTEXT ();
  81.     POP_PRIMITIVE_FRAME (3);
  82.     Install_Traps (hooks);
  83.     Store_Expression (expression);
  84.     Store_Env (environment);
  85.   }
  86.   PRIMITIVE_ABORT (PRIM_NO_TRAP_EVAL);
  87.   /*NOTREACHED*/
  88. }
  89.  
  90. /* (PRIMITIVE-APPLY-STEP OPERATOR OPERANDS HUNK3)
  91.    Applies OPERATOR to OPERANDS and intalls the eval-trap,
  92.    apply-trap, and return-trap from HUNK3.  If any
  93.    trap is '(), it is a null trap that does a normal EVAL,
  94.    APPLY or return.
  95.  
  96.    Mostly a copy of Prim_Apply, since this, too, must count the space
  97.    required before actually building a frame */
  98.  
  99. DEFINE_PRIMITIVE ("PRIMITIVE-APPLY-STEP", Prim_apply_step, 3, 3, 0)
  100. {
  101.   PRIMITIVE_HEADER (3);
  102.   PRIMITIVE_CANONICALIZE_CONTEXT ();
  103.   CHECK_ARG (3, HUNK3_P);
  104.   {
  105.     SCHEME_OBJECT hooks = (ARG_REF (3));
  106.     fast long number_of_args = 0;
  107.     {
  108.       SCHEME_OBJECT procedure = (ARG_REF (1));
  109.       SCHEME_OBJECT argument_list = (ARG_REF (2));
  110.       {
  111.     fast SCHEME_OBJECT scan_list;
  112.     TOUCH_IN_PRIMITIVE (argument_list, scan_list);
  113.     while (PAIR_P (scan_list))
  114.       {
  115.         number_of_args += 1;
  116.         TOUCH_IN_PRIMITIVE ((PAIR_CDR (scan_list)), scan_list);
  117.       }
  118.     if (scan_list != EMPTY_LIST)
  119.       error_wrong_type_arg (2);
  120.       }
  121.       POP_PRIMITIVE_FRAME (3);
  122.       Install_Traps (hooks);
  123.       {
  124.     fast SCHEME_OBJECT * scan_stack = (STACK_LOC (- number_of_args));
  125.     fast SCHEME_OBJECT scan_list;
  126.     fast long i;
  127.     Will_Push (number_of_args + STACK_ENV_EXTRA_SLOTS + 1);
  128.     Stack_Pointer = scan_stack;
  129.     TOUCH_IN_PRIMITIVE (argument_list, scan_list);
  130.     for (i = number_of_args; (i > 0); i -= 1)
  131.       {
  132.         (*scan_stack++) = (PAIR_CAR (scan_list));
  133.         TOUCH_IN_PRIMITIVE ((PAIR_CDR (scan_list)), scan_list);
  134.       }
  135.     STACK_PUSH (procedure);
  136.     STACK_PUSH (STACK_FRAME_HEADER + number_of_args);
  137.     Pushed ();
  138.       }
  139.     }
  140.   }
  141.   PRIMITIVE_ABORT (PRIM_NO_TRAP_APPLY);
  142.   /*NOTREACHED*/
  143. }
  144.  
  145. /* (PRIMITIVE-RETURN-STEP VALUE HUNK3)
  146.    Returns VALUE and intalls the eval-trap, apply-trap, and
  147.    return-trap from HUNK3.  If any trap is '(), it is a null trap
  148.    that does a normal EVAL, APPLY or return.
  149. */
  150.  
  151. DEFINE_PRIMITIVE ("PRIMITIVE-RETURN-STEP", Prim_return_step, 2, 2, 0)
  152. {
  153.   PRIMITIVE_HEADER (2);
  154.   PRIMITIVE_CANONICALIZE_CONTEXT ();
  155.   CHECK_ARG (2, HUNK3_P);
  156.   {
  157.     SCHEME_OBJECT value = (ARG_REF (1));
  158.     SCHEME_OBJECT hooks = (ARG_REF (2));
  159.  
  160.     POP_PRIMITIVE_FRAME (2); 
  161.     Install_Traps (hooks);
  162.     Val = (value);
  163.     PRIMITIVE_ABORT (PRIM_NO_TRAP_POP_RETURN);
  164.   }
  165. }
  166.